﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Forget.Data;

namespace Forget.HRBLL.Model
{
    public partial class LimitInfo
    {
        private static readonly string ADDLIMITINFO = "";
        private static readonly string EDITLIMITINFO = "";
        private static readonly string DELLIMITINFO = "";
        private static readonly string SELLIMITINFO = "HR_GetLimitInfo";

        #region properties
        [DataParam(32, System.Data.SqlDbType.Int)]
        public int? LimitInfoID { get; set; }

        [DataParam(20, System.Data.SqlDbType.NVarChar)]
        public string EnID { get; set; }

        [DataParam(20, System.Data.SqlDbType.NVarChar)]
        public string NumberID { get; set; }       

        [DataParam(32, System.Data.SqlDbType.Int)]
        public int? Type { get; set; }

        [DataParam(64, System.Data.SqlDbType.BigInt)]
        public long? Attributes { get; set; }
        #endregion


        public static bool AddLimitInfo(LimitInfo lInfo)
        {
            List<SqlParameter> parms = Convert<SqlParameter>.ObjectToParms(lInfo);
            try
            {
                if (DataAccess.ExecuteNonQuery(CommandType.StoredProcedure, ADDLIMITINFO, parms.ToArray()) > 0)
                    return true;
            }
            catch (Exception ex)
            {
                Log.WriteLog("BU.AddLimitInfo", ex.Message, ex.StackTrace);
            }
            return false;
        }
        public static bool EditLimitInfo(LimitInfo lInfo)
        {
            List<SqlParameter> parms = Convert<SqlParameter>.ObjectToParms(lInfo);
            try
            {
                if (DataAccess.ExecuteNonQuery(CommandType.StoredProcedure, EDITLIMITINFO, parms.ToArray()) > 0)
                    return true;
            }
            catch (Exception ex)
            {
                Log.WriteLog("BU.EditLimitInfo", ex.Message, ex.StackTrace);
            }
            return false;
        }

        public static bool DelLimitInfo(LimitInfo lInfo)
        {
            List<SqlParameter> parms = Convert<SqlParameter>.ObjectToParms(lInfo);
            try
            {
                if (DataAccess.ExecuteNonQuery(CommandType.StoredProcedure, DELLIMITINFO, parms.ToArray()) > 0)
                    return true;
            }
            catch (Exception ex)
            {
                Log.WriteLog("BU.DelLimitInfo", ex.Message, ex.StackTrace);
            }
            return false;
        }

        public static List<LimitInfo> SelLimitInfo(LimitInfo lInfo)
        {
            List<SqlParameter> parms = Convert<SqlParameter>.ObjectToParms(lInfo);
            try
            {
                DataTable table = DataAccess.ExecuteDataTable(CommandType.StoredProcedure, SELLIMITINFO, parms.ToArray());
                return Convert<LimitInfo>.DataConvertToObject(table);                    
            }
            catch (Exception ex)
            {
                Log.WriteLog("BU.DelLimitInfo", ex.Message, ex.StackTrace);
            }
            return null;
        }
    }
}
